Opening and Closing a Document Containing Sections
When opening a document that contains sections, your application should use
the GetResource function to get the section record and the alias record for each publisher and subscriber. Set the alias field of the section record to be the
handle to the alias.
exists.
the alias field of each section record is a handle to the alias record. The
alias record is a reference to the edition container from the section's
container for a particular section, the section is registered through a shared
control block. The control block is a private field in the section record.
result code. If the RegisterSection function cannot find the edition container container for the publisher in the last place the edition was located. The
Section Write event for that section.
When a user attempts to open a document that contains multiple publishers to
the same edition, you should warn the user by displaying an alert box.
When a user opens a document that contains a subscriber (with an update
mode set to automatic), receives a new edition, and then closes the document
without making any changes to the file, you should update the document and
simply allow the user to close it. You do not need to prompt the user to save
changes to the file.
When closing a document that contains sections, you must unregister each
corresponding section record and alias record.
of registered sections and unlinks itself from the shared control block.
The following Listing illustrates how to open an existing file that contains
sections. As described earlier, you should retrieve the section and alias
resources, connect the pair through the alias field of the section record, and
techniques for retrieving resources; this listing shows one technique. If an
alias was out of date and was updated by the Alias Manager during the document. Additionally, your application must maintain its own list of
registered sections for each open document that contains sections.
// Listing. Opening a document containing sections
// Assuming inclusion of
#include <Editions.h>
// This is a sample declaration for the pointer to your document information.
typedef struct {
short resForkRefNum;
short nextSectionID;
} *MyDocumentInfoPtr;
// This is how you would prototype this routine.
void OpenExistingDocument(MyDocumentInfoPtr);
void OpenExistingDocument(MyDocumentInfoPtr thisDocument)
{
AliasHandle aliasH; // Handle to alias in section handle Boolean aliasWasUpdated; // alias updated or not? OSErr registerErr; // typical error checking variable short resID; // resid of rSectionType
short thisone; // index into sections
short numberOfSections; // number of sections to index
Str255 aName; // name of resource ResType rType = rSectionType; // resource type for section // User defined function proto types.
void MyAddSectionAliasPair(MyDocumentInfoPtr ,SectionHandle, short); // Set the curResFile to be the resource fork of thisDocument.
// Find out the number of section resources.
// In determining the number of section/alias resource pairs to
// get, this code only loops for as many sections it finds.
// It is unusual to have more section resources than alias
// resources. Your code may want to check this and handle it
// appropriately. You now have a count of the number of section/ alias
// resource pairs to get. Loop to get them, connect them, and register
// the section.
for (thisone = 1; thisone <= numberOfSections; thisone++) {
// If sectionH is NIL, something could be wrong with the file.
// Be sure to check for this at this point.
// Get the resource ID of the section and use this to get the
// alias with the same resource ID.
//Detaching is not necessary but it is convenient.
// If aliasH is NIL, then there could be something wrong
// with the file. Be sure to check for this at this point.
// Detaching is not necessary, but it is convenient.
// Connect section and alias together.
(* sectionH)-> alias = aliasH;
// Register the section.
& aliasWasUpdated);
// is not registered. This is not a fatal error. Continue looping
// to register remaining sections.
// Add this section/ alias pair to your internal bookkeeping.
// The AddSectionAliasPair is a routine to accomplish this.
MyAddSectionAliasPair( thisDocument, sectionH, resID);
// If the alias has changed, make note of this. It is
// important to know this when you save. AliasHasChanged is a
// routine that will do this.
if ( aliasWasUpdated)
AliasHasChanged( sectionH);
}
}